home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Developer / StopWatch / Source / Preferences.m < prev    next >
Encoding:
Text File  |  1994-02-01  |  4.7 KB  |  209 lines

  1. /*
  2.  * For legal stuff see the file COPYRIGHT
  3.  */
  4. #import "Preferences.h"
  5.  
  6. @implementation Preferences
  7.  
  8. /* Attribute defaults */
  9. #define    DFLT_INVOICE_NUM    "0"
  10. #define DFLT_INVOICE_DIR    "/tmp"
  11. #define DFLT_HIDE_ON_AUTO    "NO"
  12. #define DFLT_SHOW_END_TIMES    "NO"
  13. #define DFLT_CONSULTANT_INFO    ""
  14.  
  15. /* Positions in the Form */
  16. #define    MY_NAME_POS        0
  17. #define    MY_COMPANY_POS        1
  18. #define    MY_STREET_POS        2
  19. #define    MY_CITY_POS        3
  20. #define    MY_STATE_POS        4
  21. #define    MY_ZIP_POS        5
  22. #define MY_PHONE_POS        6
  23. #define    MY_FAX_POS        7
  24. #define    MY_EMAIL_POS        8
  25.  
  26. static BOOL
  27. yes( const char *attr )
  28. {
  29.   const char *value = GET_DEFAULT(attr);
  30.   return ( value && strcmp( value, "YES") == 0 ? YES : NO );
  31. }
  32.  
  33. + initialize
  34. {
  35.   static NXDefaultsVector dflts = {
  36.     { INVOICE_NUM,    DFLT_INVOICE_NUM },
  37.     { INVOICE_DIR,    DFLT_INVOICE_DIR },
  38.     { HIDE_ON_AUTO,    DFLT_HIDE_ON_AUTO },
  39.     { SHOW_END_TIMES,    DFLT_SHOW_END_TIMES },
  40.     { MY_NAME,        "" },
  41.     { MY_COMPANY,    "" },
  42.     { MY_STREET,    "" },
  43.     { MY_CITY,        "" },
  44.     { MY_STATE,        "" },
  45.     { MY_ZIP,        "" },
  46.     { MY_PHONE,        "" },
  47.     { MY_FAX,        "" },
  48.     { MY_EMAIL,        "" },
  49.     { NULL }
  50.   };
  51.  
  52.   NXRegisterDefaults( OWNER, dflts ) ;
  53.   return self ;
  54. }
  55.  
  56. /*
  57.  * Allow only one preferences object for this app
  58.  */
  59. + new
  60. {
  61.   static id prefs;
  62.  
  63.   if ( ! prefs ) {
  64.     prefs = [[Preferences alloc] init];
  65.     [NXApp loadNibSection:"Preferences.nib" owner:prefs withNames:NO];
  66.     [prefs revert:nil];
  67.   }
  68.     
  69.   return prefs;
  70. }
  71.  
  72. /*
  73.  * Called by the controller to see if we should hide ourselves.
  74.  * Return YES if we were autolaunched and the user said to hide.
  75.  */
  76. - (BOOL)hideOnAutoLaunch
  77. {
  78.   return( yes( "NXAutoLaunch" ) && yes(HIDE_ON_AUTO) );
  79. }
  80.  
  81. - (BOOL)showEndTimes
  82. {
  83.   return( yes(SHOW_END_TIMES) );
  84. }
  85.  
  86. - display
  87. {
  88.   [invoiceNumberText selectText:nil];
  89.   [window makeKeyAndOrderFront:self];
  90.   return self;
  91. }
  92.  
  93. - chooseDir:sender
  94. {
  95.   OpenPanel *panel = [OpenPanel new];
  96.   int result;
  97.  
  98.   [panel chooseDirectories:YES];
  99.   result = [panel runModalForDirectory:NXHomeDirectory() file:""];
  100.   if ( result != NX_RUNABORTED )
  101.     [directoryText setStringValue:[panel filename]];
  102.   return self;
  103. }
  104.  
  105. - ok:sender
  106. {
  107.   PUT_DEFAULT( INVOICE_NUM,   [invoiceNumberText stringValue] ) ;
  108.   PUT_DEFAULT( INVOICE_DIR,   [directoryText stringValue] ) ;
  109.   PUT_DEFAULT( HIDE_ON_AUTO,  [hideButton state]     ? "YES" : "NO" ) ;
  110.   PUT_DEFAULT( SHOW_END_TIMES,[endTimesButton state] ? "YES" : "NO" ) ;
  111.  
  112.   PUT_DEFAULT( MY_NAME,    [form stringValueAt:MY_NAME_POS] );
  113.   PUT_DEFAULT( MY_COMPANY, [form stringValueAt:MY_COMPANY_POS] );
  114.   PUT_DEFAULT( MY_STREET,  [form stringValueAt:MY_STREET_POS] );
  115.   PUT_DEFAULT( MY_CITY,    [form stringValueAt:MY_CITY_POS] );
  116.   PUT_DEFAULT( MY_STATE,   [form stringValueAt:MY_STATE_POS] );
  117.   PUT_DEFAULT( MY_PHONE,   [form stringValueAt:MY_PHONE_POS] );
  118.   PUT_DEFAULT( MY_ZIP,     [form stringValueAt:MY_ZIP_POS] );
  119.   PUT_DEFAULT( MY_FAX,     [form stringValueAt:MY_FAX_POS] );
  120.   PUT_DEFAULT( MY_EMAIL,   [form stringValueAt:MY_EMAIL_POS] );
  121.  
  122.   [window close];
  123.   return self;
  124. }
  125.  
  126. - revert:sender
  127. {
  128.   NXUpdateDefaults() ;        /* reload the table from the database */
  129.  
  130.   [invoiceNumberText setStringValue:GET_DEFAULT(INVOICE_NUM)];
  131.   [directoryText     setStringValue:GET_DEFAULT(INVOICE_DIR)];
  132.   [hideButton        setState:yes(HIDE_ON_AUTO)];
  133.   [endTimesButton    setState:yes(SHOW_END_TIMES)];
  134.  
  135.   [form setStringValue:GET_DEFAULT(MY_NAME)    at:MY_NAME_POS];
  136.   [form setStringValue:GET_DEFAULT(MY_COMPANY) at:MY_COMPANY_POS];
  137.   [form setStringValue:GET_DEFAULT(MY_STREET)  at:MY_STREET_POS];
  138.   [form setStringValue:GET_DEFAULT(MY_CITY)    at:MY_CITY_POS];
  139.   [form setStringValue:GET_DEFAULT(MY_STATE)   at:MY_STATE_POS];
  140.   [form setStringValue:GET_DEFAULT(MY_ZIP)     at:MY_ZIP_POS];
  141.   [form setStringValue:GET_DEFAULT(MY_PHONE)   at:MY_PHONE_POS];
  142.   [form setStringValue:GET_DEFAULT(MY_FAX)     at:MY_FAX_POS];
  143.   [form setStringValue:GET_DEFAULT(MY_EMAIL)   at:MY_EMAIL_POS];
  144.  
  145.   return self;
  146. }
  147.  
  148. - reset:sender
  149. {
  150.   int pos;
  151.  
  152.   [invoiceNumberText setStringValue:DFLT_INVOICE_NUM];
  153.   [directoryText     setStringValue:DFLT_INVOICE_DIR];
  154.   [hideButton        setState:yes(DFLT_HIDE_ON_AUTO)];
  155.   [endTimesButton    setState:yes(DFLT_SHOW_END_TIMES)];
  156.  
  157.   for ( pos = 0; pos <= MY_EMAIL_POS; pos++ )
  158.     [form setStringValue:"" at:pos];    
  159.  
  160.   return self;
  161. }
  162.  
  163. - (const char *)myName
  164. {
  165.   return GET_DEFAULT(MY_NAME);
  166. }
  167.  
  168. - (const char *)myCompany
  169. {
  170.   return GET_DEFAULT(MY_COMPANY);
  171. }
  172.  
  173. - (const char *)myStreet
  174. {
  175.   return GET_DEFAULT(MY_STREET);
  176. }
  177.  
  178. - (const char *)myCity
  179. {
  180.   return GET_DEFAULT(MY_CITY);
  181. }
  182.  
  183. - (const char *)myState
  184. {
  185.   return GET_DEFAULT(MY_STATE);
  186. }
  187.  
  188. - (const char *)myZip
  189. {
  190.   return GET_DEFAULT(MY_ZIP);
  191. }
  192.  
  193. - (const char *)myPhone
  194. {
  195.   return GET_DEFAULT(MY_PHONE);
  196. }
  197.  
  198. - (const char *)myFax
  199. {
  200.   return GET_DEFAULT(MY_FAX);
  201. }
  202.  
  203. - (const char *)myEmail
  204. {
  205.   return GET_DEFAULT(MY_EMAIL);
  206. }
  207.  
  208. @end
  209.